﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20170227
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:result-document encoding="utf-8" method="text" href="./generate/php/exe_proc.php">
	<xsl:variable name="StringTypeDefine" select="document('../model/0101_StringTypeDefine.xml')"/>
	<xsl:variable name="EnumTypeDefine" select="document('../model/0102_EnumTypeDefine.xml')"/>
	<xsl:variable name="BooleanTypeDefine" select="document('../model/0103_BooleanTypeDefine.xml')"/>
	<xsl:variable name="DateTypeDefine" select="document('../model/0104_DateTypeDefine.xml')"/>
	<xsl:variable name="NumberTypeDefine" select="document('../model/0105_NumberTypeDefine.xml')"/>
	<xsl:variable name="IntegerTypeDefine" select="document('../model/0106_IntegerTypeDefine.xml')"/>&lt;?php
$const = &quot;const.php&quot;;
require_once $const;
require_once DB_OCI;
require_once OCI_MSG;
/*
*日志记录
*/
function exePLog($AppId,$OpertimeStamp,$OperParadesc){
    $msg = new oci_msg();
    $sql = 'begin p_Log(:Pi_AppId ,:Pi_OperId,:Pi_Opertimestamp,:Pi_Operparadesc); end;';
    $stmt = oci_parse($GLOBALS['oci_conn'], $sql);
    oci_bind_by_name($stmt, ':Pi_AppId', $AppId);
    $Pi_Operid = '';
    oci_bind_by_name($stmt, ':Pi_Operid', $Pi_OperId);
    oci_bind_by_name($stmt, ':Pi_OpertimeStamp', $OpertimeStamp);
    oci_bind_by_name($stmt, ':Pi_OperParadesc', $OperParadesc);


    try {
        $r1 = oci_execute($stmt);
        if (!$r1) {
            $e = oci_error($stmt);
            $err_msg = substr($e['message'], strpos($e['message'], ':') + 1, strpos($e['message'], 'ORA-', 1) - strpos($e['message'], ':') - 1);
            throw new Exception($err_msg, $e['code']);
        }
    } catch (Exception $e) {
        $msg->setOciMsg($e->getMessage());
        $msg->setOciCode($e->getCode());
    }
    oci_free_statement($Po_Cursor);
    oci_free_statement($stmt);
    return $msg;
}
<xsl:for-each select="FunNoConfig/FunNo">
/*
*<xsl:value-of select="@label"/>
*/
function exe<xsl:value-of select="@code"/>(<xsl:for-each select="Request"><xsl:for-each select="Column">$<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>
</xsl:for-each>){
    $msg = new oci_msg();
    $Pi_Operid = '';
    $Pi_Opertimestamp = '';
    $Pi_Operparadesc = '';
    exePLog(__FUNCTION__,$Pi_Opertimestamp,$Pi_Operparadesc);
    $sql = 'begin <xsl:value-of select="@code"/>(:Po_Cursor, :Pi_Operid ,:Pi_Opertimestamp,:Pi_Operparadesc<xsl:for-each select="Request"><xsl:for-each select="Column">,:Pi_<xsl:value-of select="@name"/></xsl:for-each>
</xsl:for-each>); end;';
    $stmt = oci_parse($GLOBALS['oci_conn'], $sql);
    $Po_Cursor = oci_new_cursor($GLOBALS['oci_conn']);
    oci_bind_by_name($stmt, ':Po_Cursor', $Po_Cursor, - 1, OCI_B_CURSOR);

    oci_bind_by_name($stmt, ':Pi_Operid', $Pi_Operid);

    oci_bind_by_name($stmt, ':Pi_Opertimestamp', $Pi_Opertimestamp);

    oci_bind_by_name($stmt, ':Pi_Operparadesc', $Pi_Operparadesc);
<xsl:for-each select="Request"><xsl:for-each select="Column">
    oci_bind_by_name($stmt, ':Pi_<xsl:value-of select="@name"/>', $<xsl:value-of select="@name"/>);
</xsl:for-each>
</xsl:for-each>
<xsl:variable name="Resonse" select="count(Response)"/><xsl:choose><xsl:when test="$Resonse!=0">
    try {
        $r1 = oci_execute($stmt);
        if ($r1) {
            $r2 = oci_execute($Po_Cursor);
            if ($r2) {
                $i = 0;
                $data = array();
                while (($row = oci_fetch_array($Po_Cursor, OCI_BOTH + OCI_RETURN_NULLS))) {
                    $data[$i] = $row;
                    $i = $i + 1;
                }
                $msg->setOciData($data);
            } else {
                $e = oci_error($Po_Cursor);
                $err_msg = substr($e['message'], strpos($e['message'], ':') + 1, strpos($e['message'], 'ORA-', 1) - strpos($e['message'], ':') - 1);
                throw new Exception($err_msg, $e['code']);
            }
        } else {
            $e = oci_error($stmt);
            $err_msg = substr($e['message'], strpos($e['message'], ':') + 1, strpos($e['message'], 'ORA-', 1) - strpos($e['message'], ':') - 1);
            throw new Exception($err_msg, $e['code']);
        }
    } catch (Exception $e) {
        $msg->setOciMsg($e->getMessage());
        $msg->setOciCode($e->getCode());
    }
 </xsl:when><xsl:otherwise>
    try {
        $r1 = oci_execute($stmt);
        if (!$r1) {
            $e = oci_error($stmt);
            $err_msg = substr($e['message'], strpos($e['message'], ':') + 1, strpos($e['message'], 'ORA-', 1) - strpos($e['message'], ':') - 1);
            throw new Exception($err_msg, $e['code']);
        }
    } catch (Exception $e) {
        $msg->setOciMsg($e->getMessage());
        $msg->setOciCode($e->getCode());
    }
 </xsl:otherwise></xsl:choose>

    oci_free_statement($Po_Cursor);
    oci_free_statement($stmt);
    return $msg;
}
</xsl:for-each>
?&gt;
</xsl:result-document></xsl:template>  
</xsl:stylesheet>